<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
a {
	text-decoration: none;
}

body {
	margin-top: 50px;
	margin-left: 180px;
}

th, td {
	padding: 6px 0;
	text-align: center;
}

th {
	background-color: #007D28;
	color: #ffffff;
}
tr {
  background-color:#E8FFE8;
 }

.odd {
	background-color: #FFF3EE;
}

.highlight {
	background-color: #E0E0E0;
}

table {
	border-collapse: collapse;
	text-align: center;
	width: 1000px;
	margin-top: 100px;
	margin-left: 180px;
}
/* .yh1{
background:#d7e7f9;
height: 50px;
}
.yonghu{
text-align: center;
background: #e7f2fe;
height: 30px;
}
.yh3{
text-align:center;
height: 30px;
background: #d7e7f9;
font-weight: bolder;
} */
#bg {
	display: none;
	position: absolute;
	top: 0%;
	left: 0%;
	width: 100%;
	height: 100%;
	background-color: black;
	z-index: 1001;
	-moz-opacity: 0.7;
	opacity: .70;
	filter: alpha(opacity = 70);
}

#edit {
	display: none;
	position: absolute;
	top: 25%;
	left: 30%;
	width: 32%;
	height: 35%;
	padding: 8px;
	border: 8px solid #E8E9F7;
	background-color: white;
	z-index: 1002;
	overflow: auto;
}

#edit h2 {
	text-align: center;
	font-size: 20px;
}

#edit h2 {
	text-align: center;
	font-size: 20px;
}

.in {
	margin-left: 10px;
	width: 400px;
}

.btn {
	height: 50px;
	width: 100px;
	margin: 20px;
	margin-left: 50px;
	font-size: 15px;
}
</style>
<script type="text/javascript" src="/back/js/jquery-2.1.3.min.js"></script>
<script>
	$(function() {
		$("#but").click(function() {
			$("#bg").show();
			$("#edit").show();
		});
		$("#exit").click(function() {
			$("#bg").hide();
			$("#edit").hide();
		});
		$(".del").click(
				function() {
					var num = $(this).parent().prev().prev().prev().prev()
							.prev().html();
					$.ajax({
						type : "POST",
						url : "DelAdminServlet",
						data : {
							"id" : num
						},
						dataType : "json",
						success : function(data) {
							if (data == 1) {
								alert("删除成功")
								window.location.reload()
							} else {
								alert("删除失败")
							}
						},
						error : function() {
							alert(2)
						}
					});
				});
		$(".up").click(
				function() {
					var num = $(this).parent().prev().prev().prev().prev()
							.prev().html();
					var flag = $(this).val();
					$.ajax({
						type : "POST",
						url : "DelAdminServlet",
						data : {
							"uid" : num,
							"state" : flag
						},
						dataType : "json",
						success : function(data) {
							if (data == 1) {
								alert("修改成功")
								window.location.reload()
							} else {
								alert("修改失败")
							}
						},
						error : function() {
							alert(2)
						}
					});
				});
		$(".select").change(
				function() {
					var m = $(this).val();
					var num = $(this).parent().prev().prev().prev().prev()
							.prev().prev().html();
					$.ajax({
						type : "POST",
						url : "ChangeStateServlet",
						data : {
							"uid" : num,
							"state" : m
						},
						dataType : "json",
						success : function(data) {
							if (data == 1) {
								alert("修改成功")
								window.location.reload()
							} else {
								alert("修改失败")
							}
						},
						error : function() {
							alert(2)
						}
					});
				});

	});
	$(function() {
		$("tr:even").css("background-Color", "lightblue");

	})

	//动态给js添加class属性
	function addClass(element, value) {
		if (!element.className) {
			element.className = value; //如果element本身不存在class,则直接添加class为value的值
		} else {
			element.className += " " + value; //如果element之前有一个class值，注意中间要多一个空格,然后再加上value的值
		}
	}

	//隔行换色
	function stripeTable() {
		var tables = document.getElementsByTagName("table"); //遍历文档中的所有table
		for (var i = 0; i < tables.length; i++) {
			var rows = document.getElementsByTagName("tr");
			for (var j = 0; j < rows.length; j++) {
				if (j % 2 == 0) {
					addClass(rows[j], "odd"); //如是偶数行，则添加class为odd的属性
					//rows[j].setAttribute("class", "odd");
				}
			}
		}
	}

	//鼠标经过时高亮显示
	function highlightRows() {
		var rows = document.getElementsByTagName("tr");
		for (var i = 0; i < rows.length; i++) {
			rows[i].oldClassName = rows[i].className; //首先保存之前的class值
			rows[i].onmouseover = function() {
				addClass(this, "highlight"); //鼠标经过时添加class为highlight的值
			}
			rows[i].onmouseout = function() {
				this.className = this.oldClassName; //鼠标离开时还原之前的class值
			}
		}
	}

	window.onload = function() {
		stripeTable();
		highlightRows();
	}
</script>
</head>
<body>
	<h1 style="margin-left: 550px;margin-top: 120px">管理员权限管理</h1>

	<div class="content">
		<table border="1px">
			<tr>
				<th class="yh1">编号</th>
				<th class="yh1">管理员姓名</th>
				<th class="yh1">密码</th>
				<th class="yh1">管理员等级</th>
				<th class="yh1">管理员状态</th>
				<th class="yh1">操作||<a href="#" id="but">新增管理员</a></th>
				<th class="yh1">权限更改</th>
			</tr>
			<c:forEach items="${list }" var="t">
				<tr>
					<td class="yonghu">${t.admid }</td>
					<td class="yonghu">${t.aname }</td>
					<td class="yonghu">${t.apass }</td>
					<c:if test="${t.admtype==0 }">
						<td class="yonghu">超级管理员</td>
					</c:if>
					<c:if test="${t.admtype==1 }">
						<td class="yonghu">列车管理员</td>
					</c:if>
					<c:if test="${t.admtype==2 }">
						<td class="yonghu">用户管理员</td>
					</c:if>
					<c:if test="${t.admtype==3 }">
						<td class="yonghu">完全管理员</td>
					</c:if>
					<c:choose>
						<c:when test="${t.astate==0 }">
							<td class="yonghu">正常</td>
						</c:when>
						<c:otherwise>
							<td class="yonghu">冻结</td>
						</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${t.admtype==0 }">
							<td class="yonghu" colspan="2">无法对超级管理员操作</td>
						</c:when>
						<c:otherwise>
							<c:if test="${t.astate==0 }">
								<td class="yonghu"><input class="del" type="button"
									value="删除"> <input type="button" class="up" value="冻结">
								</td>
							</c:if>
							<c:if test="${t.astate==1 }">
								<td class="yonghu"><input class="del" type="button"
									value="删除"> <input type="button" class="up" value="解冻">
								</td>
							</c:if>
						</c:otherwise>
					</c:choose>
					<c:if test="${t.admtype ne 0 }">
						<td class="yonghu"><select class="select">
								<c:if test="${t.admtype==1 }">
									<option value="1">列车管理员</option>
									<option value="2">用户管理员</option>
									<option value="3">完全管理员</option>
								</c:if>
								<c:if test="${t.admtype==2 }">

									<option value="2">用户管理员</option>
									<option value="1">列车管理员</option>
									<option value="3">完全管理员</option>
								</c:if>
								<c:if test="${t.admtype==3 }">
									<option value="3">完全管理员</option>
									<option value="1">列车管理员</option>
									<option value="2">用户管理员</option>
								</c:if>
						</select></td>
					</c:if>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="7" class="yh3"><span>第${requestScope.pageIndex }页--共${requestScope.totalPage }页</span>
					<a
					href="${pageContext.request.contextPath}/BackGuanliServlet?pageIndex=1">首页</a>
					<a
					href="${pageContext.request.contextPath}/BackGuanliServlet?pageIndex=${pageIndex-1 }">上一页</a>
					<a
					href="${pageContext.request.contextPath}/BackGuanliServlet?pageIndex=${pageIndex+1 }">下一页</a>
					<a
					href="${pageContext.request.contextPath}/BackGuanliServlet?pageIndex=${totalPage }">尾页</a>
				</td>
			</tr>
		</table>
	</div>
	<div id="bg"></div>
	<div id="edit">
		<form action="${pageContext.request.contextPath}/AddAdminServlet"
			method="post" onsubmit="return All()">
			<h2>新增管理员</h2>
			<span>姓名:</span><input type="text" name="name" id="name" class="in"
				placeholder="请输入管理员账号" onblur="checkTrueName()"><br>
			<div id="A1" style="background-color: #FFF; display: none"></div>
			<span>口令:</span><input type="text" name="pass" id="idcard" class="in"
				placeholder="请输入管理员登录口令" onblur="checkIDCard()"><br>
			<div id="A2" style="background-color: #FFF; display: none"></div>
			<span id="msg"></span><br> <span>权限：</span><input type="radio"
				name="zhuangtai" value="1">列车管理员 <input type="radio"
				name="zhuangtai" value="2">用户管理员 <input type="radio"
				name="zhuangtai" value="3">完全管理员<br> <input
				type="submit" value="确认" class="btn" id="st"><input
				type="button" id="exit" value="取消" class="btn">
		</form>
	</div>

</body>
</html>